package com.ketangabc.sdk;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.e9ab98e991ab.libcommon.base.BaseActivity;
import com.e9ab98e991ab.libcommon.base.recycle.BaseRecyclerAdapter;
import com.e9ab98e991ab.libcommon.base.recycle.SmartViewHolder;
import com.e9ab98e991ab.libcommon.utils.AppUtils;
import com.e9ab98e991ab.libcommon.utils.Utils;
import com.google.common.collect.Lists;
import com.xiaobanlong.main.R;
import com.ketangabc.sdk.Permission.VoicePermission;
import com.ketangabc.sdk.Utils.DetectingAudioHardware;
import com.ketangabc.sdk.record.LiveRecording;
import com.ketangabc.sdk.record.Player;
import com.ketangabc.sdk.record.RecordListener;
import com.ketangabc.sdk.record.Recorder;

import java.util.List;

import me.jessyan.autosize.utils.AutoSizeUtils;

public class RecordMainActivity extends BaseActivity implements  RecordListener {

    private RecyclerView rv;
    private List<String> list ;
    private BaseRecyclerAdapter<String> adapter;

    private TextView tv;
    @Override
    public int getLayoutId() {
        return R.layout.record_main;
    }

    @Override
    public void initSet() {
        tv = (TextView)findViewById(R.id.tv);


        list = Lists.newArrayList(
                "录音",
                "播放",
                "直接播放",
                "检测音频硬件AM",
                "检测音频硬件(ADBSHELL)"
        );


        new VoicePermission().initPermission(this);
    }

    @Override
    public void initDate() {


        rv = (RecyclerView)findViewById(R.id.recordRv);
        rv.setLayoutManager(new GridLayoutManager(this, AppUtils.getGridItemSize(this,AutoSizeUtils.dp2px(this,100))));

        adapter = new BaseRecyclerAdapter<String>(list, R.layout.item_adapter) {
            @Override
            protected void onBindViewHolder(SmartViewHolder holder, String model, int position) {
                holder.text(R.id.item, model);
            }

        };
        rv.setAdapter(adapter);

        adapter.setOnItemClickListener((parent, view, position, id) -> {
            switch (position) {
                case 0:
                    Recorder.getInstance().setListener(this).start(this);
                    break;
                case 1:
                    Player.getInstance().start(this);
                    break;
                case 2:
                    LiveRecording.getInstance().start(this);
                    break;
                case 3:
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        tv.setText(DetectingAudioHardware.detectUsbAudioDevice(this));
                    }
                    break;
                case 4:
                    tv.setText(DetectingAudioHardware.detectInputDeviceWithShell());
                    break;
                case 5:
//                    startActivity(new Intent(this, SpeechActivity.class));
                    break;
                default:
                    break;
            }
        });
    }



    @Override
    public void onComplete(String path) {
        tv.setText(path);
    }

    @Override
    public void onCancel() {

    }



}
